﻿using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yy.Common
{
    /// <summary>
    /// Log4net帮助类
    /// </summary>
    public class Log4Helper
    {
        /// <summary>
        /// 类别
        /// </summary>
        private Type t { get; set; }

        /// <summary>
        /// 配置
        /// </summary>
        private string cfg { get; set; }

        /// <summary>
        /// 日志
        /// </summary>
        public log4net.ILog Log { get; set; }

        /// <summary>
        /// 获取构造函数实例
        /// </summary>
        /// <typeparam name="type">类型</typeparam>
        /// <param name="config">配置</param>
        /// <returns></returns>
        public static Log4Helper GetInstance(Type type, string config)
        {
            return new Log4Helper(type, config);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Log4Helper(Type type, string config)
        {
            this.t = type;
            this.cfg = config;

            var logCfg = new FileInfo(this.cfg);

            XmlConfigurator.ConfigureAndWatch(logCfg);

            this.Log = log4net.LogManager.GetLogger(this.t);
        }
    }
}
